﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Xml.Serialization;
using Landpy.CruiseControlNet.Infrastructure.Control;

namespace Landpy.CruiseControlNet.FacadeInterface.ConfigurationModule
{
    public class Email : Publisher
    {
        [Category("Basic")]
        [Description("The SMTP server port number.")]
        [XmlAttribute("mailport")]
        public int Mailport { get; set; }

        [Category("Basic")]
        [Description("Whether to send a full report or not. If not, just sends a simple status message with a link to the build report.")]
        [XmlAttribute("includeDetails")]
        public string IncludeDetails { get; set; }

        [Category("Basic")]
        [Description("The user name to provide to the SMTP server.")]
        [XmlAttribute("mailhostUsername")]
        public string MailhostUsername { get; set; }

        [Category("Basic")]
        [Description("The password to provide to the SMTP server.")]
        [XmlAttribute("mailhostPassword")]
        public string MailhostPassword { get; set; }

        [Category("Basic")]
        [Description("Whether to use SSL or not for sending the e-mail.")]
        [XmlAttribute("useSSL")]
        public string UseSSL { get; set; }

        [Category("Basic")]
        [Description("The e-mail address that email will be marked as coming from.")]
        [XmlElement("from")]
        public string From { get; set; }

        [Category("Basic")]
        [Description("The SMTP server that CruiseControl.NET will connect to to send email.")]
        [XmlElement("mailhost")]
        public string Mailhost { get; set; }

        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [Category("Basic")]
        [Description("A set of <user> elements that define who to send emails to.")]
        [XmlArray("users")]
        [XmlArrayItem("user", Type = typeof(User))]
        public List<User> Users { get; set; }

        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [Category("Basic")]
        [Description("A set of <group> elements that identify which the notification policy for a set of users.")]
        [XmlArray("groups")]
        [XmlArrayItem("group", Type = typeof(Group))]
        public List<Group> Groups { get; set; }

        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [Category("Basic")]
        [Description("A set of <NotificationType> elements, specifying build states for which CruiseControl.Net should send an email to the comitters of the build.")]
        [XmlArray("modifierNotificationTypes")]
        [XmlArrayItem("NotificationType", typeof(NotificationType))]
        public List<NotificationType> ModifierNotificationTypes { get; set; }

        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [Category("Basic")]
        [Description("A set of <subject> elements that define the subject of the email, according to the state of the build (broken, fixed, ...)")]
        [XmlArray("subjectSettings")]
        [XmlArrayItem("subject", Type = typeof(Subject))]
        public List<Subject> SubjectSettings { get; set; }

        [Editor(typeof(MultipleTypeCollectionEditor), typeof(UITypeEditor))]
        [Category("Basic")]
        [Description("A list of xsl files that will be used to fill up the message body, if left blank the list will be taken from ccnet.exe.config or ccservice.exe.config.")]
        [XmlArray("xslFiles")]
        [XmlArrayItem("file", Type = typeof(XslFile))]
        public List<XslFile> XslFiles { get; set; }

        public Email()
            : base(PublisherType.Email)
        {
            this.Users = new List<User>();
            this.Groups = new List<Group>();
            this.ModifierNotificationTypes = new List<NotificationType>();
            this.SubjectSettings = new List<Subject>();
            this.XslFiles = new List<XslFile>();
        }
    }
}